package com.zry.admin.controller.goods;


import com.zry.admin.model.RespBean;
import com.zry.admin.service.IGoodsTypeService;
import com.zry.admin.dto.TreeDto;
import com.zry.admin.pojo.GoodsType;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 张瑞洋
 * @title: GoodsController
 * @projectName zry_jxc
 * @description: 商品类别表 前端控制器
 * @date 2022/1/21 20:19
 */
@Controller
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Resource
    private IGoodsTypeService goodsTypeService;

    @RequestMapping("queryAllGoodsTypes")
    @ResponseBody
    public List<TreeDto> queryAllGoodsTypes(Integer typeId) {
        return goodsTypeService.queryAllGoodsTypes(typeId);
    }

    @RequestMapping("index")
    public String index() {
        return "goodsType/goods_type";
    }


    @RequestMapping("list")
    @ResponseBody
    public Map<String, Object> goodsTypeList() {
        return goodsTypeService.goodsTypeList();
    }


    @RequestMapping("addGoodsTypePage")
    public String addGoodsTypePage(Integer pId, Model model) {
        model.addAttribute("pId", pId);
        return "goodsType/add";
    }

    @RequestMapping("save")
    @ResponseBody
    public RespBean saveGoodsType(GoodsType goodsType) {
        goodsTypeService.saveGoodsType(goodsType);
        return RespBean.success("商品类别添加成功");
    }


    @RequestMapping("delete")
    @ResponseBody
    public RespBean deleteGoodsType(Integer id) {
        goodsTypeService.deleteGoodsType(id);
        return RespBean.success("商品类别删除成功");
    }
}
